{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Newton Raphson Method.ipynb",
      "provenance": [],
      "authorship_tag": "ABX9TyNcCW3I8TlPU4XXyRVUCRlS",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/Divyanshu-ISM/Oil-and-Gas-data-analysis/blob/master/Newton_Raphson_Method.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "n4w1n3gqHyx7",
        "colab_type": "text"
      },
      "source": [
        "# Finding the square root of a number using python"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TUJcCDKhHGmV",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# ALGORITHM (Newton Raphson's Numerical Method)\n",
        "# x2 = N \n",
        "# f(x) = x2 - N = 0 \n",
        "# f'(x) = 2x\n",
        "# x(n+1) = x(n) - f(x)/f'(x)"
      ],
      "execution_count": 12,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "k58CqIPsH-cN",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Ask the user for an input n (the number who's square root is desired)."
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TaidU1LOIoh6",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 102
        },
        "outputId": "3c09a1b0-470a-4a94-e84d-1877928d7379"
      },
      "source": [
        "n = input(\"\\n Enter the number to be square rooted--\")\n",
        "\n",
        "n = float(n)\n",
        "\n",
        "#Let's assume the initial root (guess) be 0\n",
        "\n",
        "x = 0.1 \n",
        "\n",
        "while  (abs(x**2 - n)>0.00001) :\n",
        "  x = x - ((x**2 - n)/(2*x))\n",
        "\n",
        "\n",
        "print(f\"\\n \\n Result: The square root of {n} is {x}\")\n"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "\n",
            " Enter the number to be square rooted--784\n",
            "\n",
            " \n",
            " Result: The square root of 784.0 is 28.000000000011013\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XfxGPDUxIx6z",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}